import urllib.request
url = 'https://www.baidu.com/s?wd=ip'
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
}
# 隧道域名:端口号
tunnel = "j590.kdltps.com:15818"
# tunnel2 = "j590.kdltps.com:15818"
# tunnel = "j589.kdltps.com:15818"
# 用户名密码方式
username = "t11362165454492"
password = "oay25l6c"
proxies = {
    "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel},
    "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel}

    # "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel2},
    # "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel2}
}
request = urllib.request.Request(url=url,headers=headers)

handle = urllib.request.ProxyHandler(proxies=proxies)
operner = urllib.request.build_opener(handle)
response = operner.open(request)
content = response.read().decode('utf-8')
print(content)
with open('resource/daili.html', 'w', encoding='utf8') as fp:
    fp.write(content)